package com.bancj.demo1.controller;


import com.bancj.demo1.entity.AjaxResult;
import com.bancj.demo1.utils.AesUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * Demo
 */
@Controller
@RequestMapping("/api")
public class AesController {

    /**
     * 将前端发送的信息解密,进行加工后再加密返回给前端
     *
     * @param content 信息
     * @return
     */
    @PostMapping("/decrypt")
    @ResponseBody
    public AjaxResult getInfo(String content) throws Exception {
        System.out.println("接收到的值:" + content);
        AjaxResult ajaxResult = new AjaxResult();
        AesUtil aesUtil = new AesUtil();
        //解密
        try {
            String decrypted = aesUtil.decrypt(content);
            System.out.println("解密后的结果:" + decrypted);
            decrypted = "服务器经过解密，你传的内容是:" + decrypted;
            decrypted = aesUtil.encrypt(decrypted);
            System.out.println("----------------------------------------------------");
            ajaxResult.setObj(decrypted);
            ajaxResult.success("解密成功！");
        } catch (Exception e) {
            ajaxResult.setObj("填入的信息是无法解密的内容！");
            ajaxResult.error("内容无法解析！");
        }
        return ajaxResult;
    }

}